// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  try {
    var random = parseInt((Math.random() * 3836 + 1).toFixed(0));
    const res = await cloud.callFunction({
      // 要调用的云函数名称
      name: 'word',
      // 传递给云函数的参数
      data: {
        word_id: random,
      }
    });
    return {
      random: random,
      kana: res.result.kana,
      meaning: res.result.meaning,
    }

  } catch (e) {
    console.error(e);
  }
}